/* adt_complex.h
 * A complex (single precision only), bicomplex and quaternion numbers and arithmetic.
 * ADT (Altai Diffraction Team)
 *
 * Copyright (C) 2010 Vsevolod Scherbinin
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef ADT_COMPLEX_H
#define ADT_COMPLEX_H

// Single precision complex type
typedef struct
  {
    float dat[2];
  }
adt_complex_float;

// Single precision bicomplex type
typedef struct
  {
    float dat[4];
  }
adt_bicomplex_float;

//signum
#define ADT_SGN(val) ((val > 0. ? 1. : (val < 0. ? -1. : 0.)))

//Macros for setting
//set real part of zp to x
#define ADT_SET_REAL(zp,x) do {(zp)->dat[0]=(x);} while(0)
//set imaginary part of zp to y
#define ADT_SET_IMAG(zp,y) do {(zp)->dat[1]=(y);} while(0)
#define ADT_SET_COMPLEX(zp,x,y) do {(zp)->dat[0]=(x); (zp)->dat[1]=(y);} while(0)

//real part
#define ADT_REAL(z)     ((z).dat[0])
//imaginary part
#define ADT_IMAG(z)     ((z).dat[1])
//Equity
#define ADT_COMPLEX_EQ(z1,z2) (((z1).dat[0] == (z2).dat[0]) && ((z1).dat[1] == (z2).dat[1]))

#define ADT_SET_BICOMPLEX(bp,x0,x1,x2,x3) do {(bp)->dat[0]=(x0); (bp)->dat[1]=(x1); (bp)->dat[2]=(x2); (bp)->dat[3]=(x3);} while(0)

#include "adt_complex_internal.h"

#define ONDEVICE
#include "adt_complex_internal.h"
#undef ONDEVICE

#endif /* ADT_COMPLEX_H */